home *** CD-ROM | disk | FTP | other *** search
-
- /************************************************************************/
- #define OP_NAME "pgmbinomial"
- #define VERSION "1.06"
- #define DATE "29.01.98"
- #define AUTHOR "Stefan Diener"
- /************************************************************************/
-
- #include <stdio.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <sys/types.h>
-
- #include <STIMP/pgm.c>
-
- struct PGM_Info source, desti;
- static int m, n;
- static int edge=1;
-
- void Do_It(void)
- {
- unsigned char breite, mitte;
- int i, j, k, l, index;
- unsigned int h[25], su, factor;
- unsigned char *src, *dst;
-
- src=source.Data;
- dst=desti.Data;
- desti.maxval=source.maxval;
-
- /* Filtermaske initialisieren */
- if (edge==1)
- {
- factor=16;
- breite=3;
- mitte=4;
- h[0]=1; h[1]=2; h[2]=1;
- h[3]=2; h[4]=4; h[5]=2;
- h[6]=1; h[7]=2; h[8]=1;
- }
- else
- {
- factor=176;
- breite=5;
- mitte=12;
- h[0]=1; h[1]=4; h[2]=6; h[3]=4; h[4]=1;
- h[5]=4; h[6]=8; h[7]=14; h[8]=8; h[9]=4;
- h[10]=6; h[11]=14; h[12]=28; h[13]=14; h[14]=6;
- h[15]=4; h[16]=8; h[17]=14; h[18]=8; h[19]=4;
- h[20]=1; h[21]=4; h[22]=6; h[23]=4; h[24]=1;
- }
-
- /* Filtermaske anwenden */
- for (i=edge;i<(n-edge);i++)
- for (l=edge;l<(m-edge);l++)
- {
- index=l*n+i;
- su=0;
-
- for (j=-edge; j<=edge; j++)
- for (k=-edge; k<=edge; k++)
- su+=h[j*breite+k+mitte]*src[index+j*n+k];
-
- su=su/factor;
- dst[(l-edge)*(n-2*edge)+(i-edge)]=(su<desti.maxval) ? su : desti.maxval;
- }
- }
-
- int main(int argc,char **argv)
- /* Hauptprogramm */
- {
- int i;
-
- /* offizielle Begruessung */
- PrintOpening(argc, argv);
-
- /* Uebergebene Parameter auswerten */
- for (i=1; i<argc; i++)
- {
- if ((argv[i][0]=='-') && argv[i][1])
- {
- switch (argv[i][1])
- {
- case '3': edge=1;
- break;
-
- case '5': edge=2;
- break;
-
- case 'v': beVerbose=FALSE;
- break;
-
- default: PrintMessage("Unknown parameter: %s", argv[i]);
- Hilfe();
- exit(-1);
- break;
- }
- }
-
- if (argv[i][0]=='+')
- {
- switch (argv[i][1])
- {
- case 'v': beVerbose=TRUE;
- break;
-
- default: PrintMessage("Unknown parameter: %s", argv[i]);
- Hilfe();
- exit(-1);
- break;
- }
- }
- }
-
- /* Mindestzahl der Argumente pruefen */
- if (argc<3)
- {
- PrintMessage("Wrong number of arguments !");
- Hilfe();
- exit(-1);
- }
-
- /* Anzahl der Dateinamen überprüfen */
- if (FilenameCount(argc, argv)!=2)
- {
- PrintMessage("Wrong number of file names !");
- Hilfe();
- exit(-1);
- }
-
- if (ReadPGMFile(GetFilename(1,argc,argv), &source)==0)
- {
- m=source.height;
- n=source.width;
-
- if (CreatePGMArray(m-2*edge, n-2*edge, &desti)==0)
- {
- PrintMessage("Working ...");
- Do_It();
-
- WritePGMFile(GetFilename(2,argc,argv), &desti);
- FreePGMArray(&desti);
- }
-
- FreePGMArray(&source);
- }
-
- PrintClosing();
- exit(0);
- }
-
-